from flask import current_app
from qiniu import Auth,put_data
access_key = 'yV4GmNBLOgQK-1Sn3o4jktGLFdFSrlywR2C-hvsW'
secret_key = 'bixMURPL6tHjrb8QKVg2tm7n9k8C7vaOeQ4MEoeW'
buck_name = 'ihome'


def storage(path):
    if not path:
        return None
    try:
        q = Auth(access_key,secret_key)
        token = q.upload_token(buck_name)
        ret,info = put_data(token,None,path)
        print(ret["key"])
        print('测试文件')
    except Exception as ret:
        current_app.logger.error()
        raise ret

    if info and info.status_code != 200:
        raise Exception("上传文件失败")
    return ret["key"]

if __name__ == '__main__':
    storage(input('file path is :'))
